package tests;

import mastermind.game.GameException;
import mastermind.game.Pieces;

import org.junit.Assert;
import org.junit.Test;

public class PieceTests {
	 
	@Test
	public void test1() throws GameException {
		pieceCompare("gymb", "gymm", "bbb");
	}
	
	@Test
	public void test2() throws GameException {
		pieceCompare("gymb", "rgyp", "ww");
	}
	
	@Test
	public void test3() throws GameException {
		pieceCompare("gymb", "ygrr", "ww");
	}
	
	@Test
	public void test4() throws GameException {
		pieceCompare("gymb", "gyoc", "bb");
	}
	
	@Test
	public void test5() throws GameException {
		// assignment spec says 'wbb' expected here, but this is the same
		pieceCompare("gymb", "gyym", "bbw");
	}
	
	@Test
	public void test6() throws GameException {
		pieceCompare("gymb", "gymb", "bbbb");
	}
	
	@Test
	public void test7() throws GameException {
		pieceCompare("gymb", "cccc", "");
	}
	
	private void pieceCompare(String secret, String guess, String expect) throws GameException {
		Pieces s = new Pieces(secret.toCharArray());
		Pieces g = new Pieces(guess.toCharArray());
		String response = s.feedback(g);
		System.out.printf("'%s' '%s'\n", expect, response);
		Assert.assertTrue(response.equals(expect));
		
		/* make sure the pieces haven't been changed */
		Assert.assertTrue(new String(s.getPieces()).equals(secret));
		Assert.assertTrue(new String(g.getPieces()).equals(guess));
	}
}
